<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">   
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">  
  <head>
    <base target="_self"/>
    <title>修改角色信息</title>
    <%@ include file="../jslib/jquerylib.jsp" %> 
	 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath() %>/web/style/layout4.css" />
	 <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/jquery.form.js"></script>
	 <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
     <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
	 <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
     <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>

    <c:if test="${requestScope.message!=null}">
			<script type="text/javascript">
  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
  			</script>
	    </c:if>
		<script type="text/javascript"> 
    var api = frameElement.api, W = api.opener, old;   
	function init(){
		var parentid = document.getElementById("parentid");		
		var rolename = document.getElementById("rolename");
		var parentName = document.getElementById("parentName");
		var rolelabel = document.getElementById("rolelabel");
		var roledesc = document.getElementById("roledesc");
		var roleId = document.getElementById("roleId");

		parentName.value = eval("("+api.data+")").parentName;
		rolename.value = eval("("+api.data+")").rolename;
		rolelabel.value=eval("("+api.data+")").rolelabel;
		roledesc.value= eval("("+api.data+")").roledesc;
		parentid.value = eval("("+api.data+")").parentid;	
		roleId.value = eval("("+api.data+")").roleId;	


		old = document.getElementById("rolename").value;
	}
	 $(document).ready(function() {
		// var old = $("#rolename").val();
		   // var old = '<c:out value="${requestScope.role.rolename}"></c:out>';
		    	// 准备好Options对象
		    	var options = {
		    			//alert(111);
		    	    url:'updateRole.action',
		    	    beforeSubmit:checkForm,
		    	    dataType:'json',
		    	    success: function(data) {		    				    	       
		    	     if(data.ajaxResult=='success'){
							alert("修改成功！");
							api.close();
							W.reload();
							}
		    	      location.reload();
		    	}};
				 $('#saveBtn').click(function(){
			    	$('#pageFrom').ajaxSubmit(options);
			            return false;
		    	 });
				$('#closeBtn').click(function(){
					api.close();
		    	 });		    
		}); 

	  //校验 
		function checkForm(){
			var flag = true;
			if($.trim($("#rolename").val())==""){
				alert("角色名称不能为空!");
				$("#rolename").focus();
				return false;
			}else if(!checkExp($("#rolename").val())){
				alert("角色名称不能含有如下特殊符号：\" # $ \, \'");
				$("#rolename").focus();
				return false;
			}else if(!(flag = checkId())){
				$("#rolename").focus();
				return false;
			}else if(!roleNameCountintlen($("#rolename").val())){
				alert("角色名称最多为40个字符,字符输入超出限制!");
				$("#rolename").focus();
				return false;
			}
			
			if($("#rolelabel").val()=="0"){
				alert("请选择角色标识!");
				$("#rolelabel").focus();
				return false;
			}

			if(!checkExp($("#roledesc").val())){
				alert("角色描述不能含有如下特殊符号：\" # $ \, \'");
				$("#roledesc").focus();
				return false;
			}else if(!rolelabelCountintlen($("#roledesc").val())){
				alert("角色描述最多为100个字符,字符输入超出限制!");
				$("#roledesc").focus();
				return false;
			}
			 return flag;
		}


		 function checkId(){
				var flag = true;
				$.ajax({
				   type: "POST",
				   async: false,//取消异步提交
				   url: "getRolesName.action",
				   dataType: "json",
				   data: {
					rolename: function(){
						//return '<c:out value="${requestScope.role.rolename}"></c:out>';
						return encodeURIComponent(document.getElementById("rolename").value);
						},
						old:encodeURIComponent(old)
				   },
				   success: function(data){
				   	 if(data.result != "success"){
				     	alert( "角色名称已存在，请重新输入！" );
				     	flag = false;
				     }
				   }
				}); 
				return flag;
			}
	 function roleNameCountintlen(input){
			var result = $("#rolename").val().length;
			if (result > 40) {
				return false;
			}else{
				return true;
			}
	}
	 function rolelabelCountintlen(input){
			var result = $("#roledesc").val().length;
			if (result > 100) {
				return false;
			}else{
				return true;
			}
	}
	
		 //验证特殊字符
		function checkExp(inputData){ 
			//var regEx = new RegExp(/^(([^\^\.<>%&',:;=?$"'#@!~\]\[{}【】￥（）！·‘’”“。，、？：；—|\/\\/`\|])*)$/);
			var regEx = new RegExp(/^(([^$,"'#])*)$/);
			var result = inputData.match(regEx);
			if (result == null) {
			return false;
			}
			return true;
		}

	//过滤表单的前后空格
	function trimkeyup(e) {
	     lucene_objInput = $(this);
	     if (e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 13) {
	        var im = $.trim(lucene_objInput.val());
	       lucene_objInput.val(im); 
	    }
	}		
    </script>
    <style type="text/css">
 		body{
 			background:#ffffff; background-image:url(images/);
 		}
   		html{
		    overflow-x: hidden;
			overflow-y: hidden;
		}  		
   </style>
  </head>
   <body onload="init()">	
		<form action="" id="pageFrom" name="" method="post" >
			<input type="hidden" id="parentid" name="parentid"/>
			<input type="hidden" id="roleId" name="roleId"/>
			<table  width="100%" border="0" align="center" cellpadding="5" cellspacing="5" class="formTableNew">
				<tr>
					<td align="right">父角色名称：</td>
					<td align="left">
						<div class="div">
							<input type="text" id="parentName" name="parentName" readonly="readonly" style="width:250px" onkeydown="if(event.keyCode==8)return false;"/>
						</div>
					</td>	
				</tr>
				<tr>
					<td align="right">角色名称：</td>
					<td >
						<div class="div">
							<input id="rolename" name="rolename" value="<s:property value='role.rolename'/>" style="width:250px" onkeydown="countlen(this);"/>
							<img src="<%=request.getContextPath()%>/images/xh.png"></img>
						</div>
					</td>
				</tr>
				<tr>
					<td align="right">角色标识：</td>
					<td >
						<div class="div">
                         <select name="rolelabel" id="rolelabel" onkeydown="if(event.keyCode==8)return false;" style="width:262px">
                               <s:property value='role.rolelabel'/>
                                <option value="0" >请选择</option>
                                <option value="ROLE_SYSADMIN" <s:if test="role.rolelabel=='ROLE_SYSADMIN'">selected</s:if>>系统管理员</option>
                                <option value="ROLE_ADMIN" <s:if test="role.rolelabel=='ROLE_ADMIN'">selected</s:if>>用户管理员</option>
                                <option value="ROLE_OPERATOR" <s:if test="role.rolelabel=='ROLE_OPERATOR'">selected</s:if>>操作员</option>
                                <option value="ROLE_MAINTENANCE" <s:if test="role.rolelabel=='ROLE_MAINTENANCE'">selected</s:if>>研究员</option>                
                            </select> 
                        <img src="<%=request.getContextPath()%>/images/xh.png" alt="" />
                        </div>
                    </td>
				</tr>
				<tr>
					<td align="right">
						角色描述：
					</td>
					<td >
						<div class="div">
							<textarea rows="8" cols="50" id="roledesc" name="roledesc" style="width:250px" onkeydown="countlen(this);"><s:property value='role.roledesc'/></textarea>
						</div>
					</td>
				</tr>
					<tr>
					<td align="center" colspan="2">
						<input type="button" id="saveBtn" class="form_bt_orange" value="保存"/>
						<input type="button" id="closeBtn" class="form_bt_grey" value="取消 "/>
					</td>
				</tr>
			</table>	
		</form>					
	</body>
</html>
